{% extends "layout.html" %}

{% block page_title %}Posts Management{% endblock %}

{% block admin_content %}

<div id="posts_container" class="span10 offset1">
    {% if alert_message %}
        <div class="alert alert-info">
            <a class="close" data-dismiss="alert">&times;</a>
            <strong>{{ _("Information") }}!</strong> {{ alert_message }}
        </div>
    {% endif %}

    <table class="table table-hover">
        <caption><h3 class="pull-left">All Posts for Your Blog:</h3></caption>
        <thead class="">
            <tr>
                <td>{{ _("Title") }}</td>
                <td>{{ _("Date") }}</td>
                <td>{{ _("Published?") }}</td>
                <td>{{ _("Operations") }}</td>
            </tr>
        </thead>
        <tbody>
    {% for post in posts %}
        <tr class="">
            <td>{{ post.title }}</td>
            <td>{{ post.date }}</td>
            <td>{% if post.is_external_page %}
                <i class="icon-ok"></i>
                {% else %}
                <i class="icon-remove"></i>
                {% endif %}
            </td>
            <td>
                <div class="btn-group">
                    <a class="btn btn-mini btn-info" href="/admin/posts/{{post.key().id()}}/edit">Edit</a>
                    {% if post.is_external_page %}
                    <a class="btn btn-mini btn-info" href="/admin/posts/{{post.key().id()}}/unpublish">unPublish</a>
                    {% else %}
                    <a class="btn btn-mini btn-info" href="/admin/posts/{{post.key().id()}}/publish">Publish</a>
                    {% endif %}
                    <a class="btn btn-mini btn-danger" href="/admin/posts/{{post.key().id()}}/delete">Delete</a>
                </div>
            </td>
        </tr>
    {% endfor %}
        </tbody>
    </table>


<form class="form-horizontal" action="/admin/posts" method="post">
    <fieldset>
        <legend>{{ _("Compose your blog") }}:</legend>
        <div class="control-group">
            <label class="control-label" for="blog_title">{{ _("Title") }}</label>
            <div class="controls">
                <input type="text" class="input-xlarge" name="blog_title" value="{% if current_post %}{{current_post.title}}{% endif %}">
                <p class="help-block">{{ _("Blog title") }}</p>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="blog_slug">{{ _("Slug") }}</label>
            <div class="controls">
                <input type="text" class="input-xlarge" name="blog_slug"value="{% if current_post %}{{current_post.slug}}{% endif %}">
                <p class="help-block">{{ _("Brief title which will be used as part of URL") }}</p>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="blog_category">{{ _("Category") }}</label>
            <div class="controls">
                <select name="blog_category_id">
                {% for cate in categories %}
                    {% if current_post and current_post.category.name == cate.name %}
                        <option  value="{{ cate.key().id() }}" selected>{{ cate.name }}</option>
                    {% else %}
                        <option  value="{{ cate.key().id() }}">{{ cate.name }}</option>
                    {% endif %}
                {% endfor %}
                </select>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="blog_content">{{ _("Content") }}</label>
            <div class="controls">
                <textarea class="ckeditor" name="blog_content" rows="50">{% if current_post %}{{current_post.content}}{% endif %}</textarea>
            </div>
        </div>
        <div class="form-actions">
            <input type="hidden" class="" name="current_post_id" value="{% if current_post %} {{ current_post.key().id() }} {% endif %}">
            <button type="submit" class="btn" name="submit_action" value="save">{{ _("Save") }}</button>
            <button type="submit" class="btn" name="submit_action" value="save_publish">{{ _("Save & Publish") }}</button>
        </div>
    </fieldset>
</form>                
</div><!-- posts_container -->

{% endblock %}
